package ModelLager;
import java.util.ArrayList;

/**
 * Write a description of class OrdreContianer here.
 * 
 * @author (Gruppe 5) 
 * @version (a version number or a date)
 */
public class OrdreContainer
{
    private ArrayList<Ordre> ordrer;
    private static OrdreContainer instance;
    
    /**
     * OrdreContainer Constructor
     *
     */
    private OrdreContainer()
    {
        ordrer = new ArrayList<Ordre>();
    }
    
    /**
     * Method getInstance
     *
     * @return The return value
     */
    public static OrdreContainer getInstance()
    {
        if(instance == null)
        {
            instance = new OrdreContainer();
        }
        return instance;
    }
    
    /**
     * Method addOrdre
     *
     * @param o A parameter
     * 
     * Tilføjer en ordre til ordrer.
     */
    public void addOrdre(Ordre o)
    {
        ordrer.add(o);
    }
    
    /**
     * Method findOrdre
     *
     * @param id A parameter
     * @return The return value
     * 
     * Methoden bruger id til at finde en bestemt ordre
     * og sender så dens info tilbage eller sender null,
     */
    public Ordre findOrdre(int id)
    {
        int index = 0;
        Ordre o = null;
        boolean found = false;
        
        while(index < ordrer.size() && !found)
        {
            o = ordrer.get(index);
            
            if(o.getID() == id)
            {
                found = true;
            }
            else
            {
                index++;
            }
        }
        
        if(found)
        {
            return ordrer.get(index);
        }
        else
        {
            return null;
        }
    }
}
